{$head_meta}
<title>{$action} | {$Think.config.title}</title>
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body class="page-header-fixed">
    <!-- BEGIN HEADER -->
    <div class="header navbar navbar-inverse navbar-fixed-top">
        <!-- BEGIN TOP NAVIGATION BAR -->
        <div class="navbar-inner">
            <div class="container-fluid">
                <!-- BEGIN LOGO -->
                <a class="brand" href="{:U('Admin/Index/index')}">
                <img src="__PUBLIC__/admin/assets/img/logo.png" alt="logo" />
                </a>
                <!-- END LOGO -->
                <!-- BEGIN RESPONSIVE MENU TOGGLER -->
                <a href="javascript:;" class="btn-navbar collapsed" data-toggle="collapse" data-target=".nav-collapse">
                <img src="__PUBLIC__/admin/assets/img/menu-toggler.png" alt="" />
                </a>          
                <!-- END RESPONSIVE MENU TOGGLER -->            
                <!-- BEGIN TOP NAVIGATION MENU -->              
                <ul class="nav pull-right">
                    <!-- BEGIN USER LOGIN DROPDOWN -->
                    <li class="dropdown user">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <img alt="" src="__PUBLIC__/admin/assets/img/avatar1_small.jpg" />
                        <span class="username">{$username}</span>
                        <i class="icon-angle-down"></i>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a href="{:U('Admin/Index/index')}"><i class="icon-user"></i>个人信息</a></li>
                            <li class="divider"></li>
                            <li><a href="{:U('Admin/Login/logout')}"><i class="icon-key"></i>退出</a></li>
                        </ul>
                    </li>
                    <!-- END USER LOGIN DROPDOWN -->
                </ul>
                <!-- END TOP NAVIGATION MENU --> 
            </div>
        </div>
        <!-- END TOP NAVIGATION BAR -->
    </div>
    <!-- END HEADER -->
    <!-- BEGIN CONTAINER -->
    <div class="page-container row-fluid">
        <!-- BEGIN SIDEBAR -->
        <div class="page-sidebar nav-collapse collapse">
            <!-- BEGIN SIDEBAR MENU -->        
            <ul class="page-sidebar-menu">
                <li>
                    <!-- BEGIN SIDEBAR TOGGLER BUTTON -->
                    <div class="sidebar-toggler hidden-phone"></div>
                    <!-- BEGIN SIDEBAR TOGGLER BUTTON -->
                </li>
                {$menu}
            </ul>
            <!-- END SIDEBAR MENU -->
        </div>
        <!-- END SIDEBAR -->
        <!-- BEGIN PAGE -->
        <div class="page-content">
            <!-- BEGIN PAGE CONTAINER-->        
            <div class="container-fluid">
                <!-- BEGIN PAGE HEADER-->
                <div class="row-fluid">
                    <div class="span12">  
                        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                        <h3 class="page-title">
                            {$action}<small>&nbsp;&nbsp;{$Think.config.title}</small>
                        </h3>
                        <ul class="breadcrumb">
                            <li>
                                <a href="{$module_url}">{$module}</a>
                                <i class="icon-angle-right"></i>
                            </li>
                            <li><a href="{$action_url}">{$action}</a></li>
                        </ul>
                        <!-- END PAGE TITLE & BREADCRUMB-->
                    </div>
                </div>
                <!-- END PAGE HEADER-->
                <!-- BEGIN PAGE CONTENT-->
                <div class="row-fluid">
                    <div class="span12">
                        <h4>系统数据库备份目录下共有{$files}个SQL备份文件，共计{$total}&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:red;font-weight:bold;" id="success"></span></span></h4>
                        <!-- BEGIN EXAMPLE TABLE PORTLET-->
                        <form id="myForm">
                            <table
                                class="table table-striped table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th style="width: 8px;">选择</th>
                                        <th >SQL文件名</th>
                                        <th >备份时间</th>
                                        <th class="hidden-240">类型</th>
                                        <th class="">文件大小</th>
                                        <th class="">文件备注</th>
                                        <th class="">导入</th>
                                    </tr>
                                </thead>
                                <tbody id="cache_table">
                                    <volist name="list" id="sql">
                                    <tr id="{$sql.name|del_sql=###}" align="center">
                                        <td><input pre="{$sql.pre}" type="checkbox" name="sqlFiles" value="{$sql.name}"/></td>
                                        <td align="left"><a href="{:U('Sysdata/downFile',array('file'=>$sql['name'],'type'=>'sql'))}" target="_blank">{$sql.name}</a></td>
                                        <td>{$sql.time}</td>
                                        <td>{$sql.type}</td>
                                        <td>{$sql.size}</td>
                                        <td class="description" title="{$sql.description}">查看备注信息</td>
                                        <td><button type="button" class="btn restore" sqlPre="{$sql.pre}">导入</button></td>
                                    </tr>
                                    </volist>
                                </tbody>
                                <tfoot>
                                    <tr><th></th>
                                        <th></th>
                                        <th></th>
                                        <th></th>
                                        <th></th>
                                        <th></th>
                                        <th></th>
                                    </tr>
                                </tfoot>
                            </table><br />
                            <div class="control-group send_box" style="text-align: center; display:none;">
                                <div class="controls">
                                	<span id="input_email">请输入邮箱：&nbsp;&nbsp;</span>
                                    <input type="text" placeholder="邮箱" class="m-wrap medium" name="to" id="to" />
                                    <span class="help-inline"></span>
                                    <button type="button" class="btn send_email red">发送</button>
                                </div>
                            </div>
                            <div class="form-actions" style="text-align: center">
                                <div class="span4">
                                    <button type="button" class="btn" id="checkall">全选</button>&nbsp;&nbsp;
                                    <button type="button" class="btn blue" id="check_reverse">反选
                                    </button>&nbsp;&nbsp;
                                    <button type="button" class="btn red" id="check_cancel">取消</button>
                                </div>
                                <div class="span2">
                                    <button type="button" class="btn red delSqlFiles">
                                        <i class="m-icon-swapright m-icon-white"></i>删除所选
                                    </button>
                                </div>
                                <div class="span2">
                                    <button type="button" class="btn blue sendSql" id="sendSql">发送SQL到邮箱</button>
                                </div>
                                <div class="span2">
                                    <button type="button" class="btn blue zip" id="zip">压缩SQL为ZIP</button>
                                </div>
                            </div>

                        </form>
                        <!-- END EXAMPLE TABLE PORTLET-->
                    </div>
                </div>
                <!-- END PAGE CONTENT-->
            </div>
            <!-- END PAGE CONTAINER-->
        </div>
        <!-- END PAGE -->
    </div>
    <!-- END CONTAINER -->
    {$footer}
    {$foot_js}
    <script>
        jQuery(document).ready(function() {       
           
           $("#cache_table :checkbox").attr("checked", true);

           App.init();
           TableManaged.init();
 
            $("#checkall").click(function() { //":checked"匹配所有的复选框
                $("#cache_table :checkbox").attr("checked", true); //"#div1 :checked"之间必须有空格checked是设置选中状态。如果为true则是选中fo否则false为不选中
                $("span").addClass("checked"); 
            });
            $("#check_cancel").click(function() {
                $("#cache_table :checkbox").attr("checked", false);
                $("span").removeClass("checked"); 
            });
            //理解用迭代原理each（function(){}）
            $("#check_reverse").click(function() {
                $("#cache_table :checkbox").each(function() {
                
                    $(this).attr("checked", !$(this).attr("checked")); 
                    $(this).parentsUntil('div').toggleClass("checked");
                    
                    
                    //!$(this).attr("checked")判断复选框的状态：如果选中则取反
                });
            });

            //delSqlFiles
            $(".delSqlFiles").click(function(){
                var obj=document.getElementsByName('sqlFiles');
                // var file = [];
                var sqlFiles = '';
                for(var i = 0; i < obj.length; i++) {
                    if(obj[i].checked) {
                       // file.push({sqlFiles:obj[i].value}); 
                       if(i != obj.length - 1) {
                            sqlFiles = sqlFiles + (obj[i].value) + ',';
                       }
                       else {
                        sqlFiles += obj[i].value;
                       }
                   }
                }
                var url = '__URL__/delSqlFiles';
                $.post(url, {sqlFiles:sqlFiles}, function(data) {
                    
                    //删除成功
                    if(data.status == 1) {
                        $("#success").fadeIn().html(data.info);
                        $("#success").fadeOut(3000);

                        var to_deleted_obj=document.getElementsByName('sqlFiles');
                        var to_deleted_sqlFiles = '';
                        for(var i = 0; i < to_deleted_obj.length; i++) {
                            if(to_deleted_obj[i].checked) {
                               // file.push({sqlFiles:obj[i].value}); 
                               if(i != to_deleted_obj.length - 1) {
                                    to_deleted_sqlFiles = to_deleted_sqlFiles + (to_deleted_obj[i].value) + ',';
                               }
                               else {
                                    to_deleted_sqlFiles += to_deleted_obj[i].value;
                               }
                           }
                        }
                        var deleted = to_deleted_sqlFiles.split(',');

                        $.each(deleted, function(n, value) {
                            var name = value.replace(".sql", "");
                            var to_deleted = $('#' + name);
                            to_deleted.fadeOut();
                        });
                    }
                    else {
                        $("#success").fadeIn().html(data.info);
                        $("#success").fadeOut(3000);
                    }
                }, "json");
                
            });

            //zip
            $(".zip").click(function(){
                var obj2=document.getElementsByName('sqlFiles');
                // var file = [];
                var sqlFiles2 = '';
                for(var i = 0; i < obj2.length; i++) {
                    if(obj2[i].checked) {
                       // file.push({sqlFiles:obj[i].value}); 
                       if(i != obj2.length - 1) {
                            sqlFiles2 = sqlFiles2 + (obj2[i].value) + ',';
                       }
                       else {
                        sqlFiles2 += obj2[i].value;
                       }
                   }
                }
                var url2 = '__URL__/zipSql';
                $.post(url2, {sqlFiles:sqlFiles2}, function(data) {
                

                    //打包成功
                    if(data.status == 1) {
                        $("#success").fadeIn().html(data.info);
                        $("#success").fadeOut(3000);
                       
                        if(data.url) {
                            location.href = data.url;
                        }
                    }
                    else {
                        $("#success").fadeIn().html(data.info);
                        $("#success").fadeOut(3000);
                    }
                }, "json");
                
            });
            
            //sendSql
            $(".sendSql").click(function(){
            	$(".send_box").fadeIn();
                 if($(this).attr("disabledSubmit")){
                    
                    $("#success").fadeIn().html("已提交，系统在处理中...");
                    return false;
                } 
           });
          //提交数据恢复操作
            $(".restore").click(function(){
                if($(this).attr("disabledSubmit")){
                	 $(".restore[sqlPre='"+sqlPre+"']").attr("disabledSubmit",true).html("已提交，系统在处理中...");
                    return false;
                }
                var sqlPre=$(this).attr("sqlPre");
                $(".restore[sqlPre='"+sqlPre+"']").attr("disabledSubmit",true).html("导入中...");
                $(".btn").attr("disabledSubmit",true);
                $.getJSON("__URL__/restoreData", {sqlPre:sqlPre}, function(json){
                    if(json.status==1){
                        if(json.url){
                            $("#opStatus").show().html(json.info);
                            repeat(json.url,"restore");
                        }else{
                        	$(".restore[sqlPre='"+sqlPre+"']").attr("disabledSubmit",true).html(json.info);
                        }
                        $(".restore[sqlPre='"+sqlPre+"']").attr("disabledSubmit",true).html(json.info);
                    }else{
                    	$(".restore[sqlPre='"+sqlPre+"']").attr("disabledSubmit",true).html(json.info);
                    }
                });
                $(".restore[sqlPre='"+sqlPre+"']").attr("disabledSubmit",true).html("系统处理中请稍候....<br />可能需要较长时间");
                return false;
            });
          //刷新操作
            var repeat=function(url,type){
                $.post(url, function(json){
//                    var json = eval("(" + json + ")");
                    if(json.status==1){
                        if(json.url){
                            $("#success").fadeIn().html(json.info);
                            repeat(json.url,type);
                        }else{
                        	$("#success").fadeIn().html(json.info);
                        }
                    }else{
                    	$("#success").html(json.info);
                    }
                });
            };
           
           $(".send_email").click(function() {
        	   if($("tbody input[type='checkbox']:checked").size()==0){
               	$("#success").fadeIn().html("请选择要发送到邮件中的数据库");
               	$("#success").fadeOut(3000);
                   return false;
               }
        	   if($("#to").val() == ''){
                  	$("#input_email").css("color", "red");
                  	$("#to").css("border-color", "red");
                      return false;
                  }
               var url3 = '__URL__' + '/sendSql';
               var obj3=document.getElementsByName('sqlFiles');
               
               // var file = [];
               var sqlFiles3 = '';
               for(var i = 0; i < obj3.length; i++) {
                   if(obj3[i].checked) {
                      // file.push({sqlFiles:obj[i].value}); 
                      if(i != obj3.length - 1) {
                           sqlFiles3 = sqlFiles3 + (obj3[i].value) + ',';
                      }
                      else {
                       sqlFiles3 += obj3[i].value;
                      }
                  }
               }
               
               //alert(sqlFiles3);
               var div = $("#success");
               var to = $("#to").val();
				$.post(url3, {"sqlFiles":sqlFiles3, "to":to}, function(data) {
                   var i = 0;
                   //var data = eval("(" + data + ")");
                   
                   //发送成功
                   if(data.status == 1) {
                	   if(data.url) {
                		  
                               location.href = data.url;
                        
                    	   i++;
                       }
                       else {
                    	   div.fadeIn().html(data.info);
                           div.fadeOut(3000);
                       }
                   }
                   else {
                	   //alert(data.info);
                      	div.fadeIn().html(data.info);
                      	div.fadeOut(5000);
                   }
                   //alert(i);
               }, "json");
               
               
           });
        });
    </script>
</body>
<!-- END BODY -->
</html>